package com.app.twth.ui.finalprocess.trk;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;


import com.app.twth.databinding.ItemFinalprocessLpnListBinding;
import com.app.twth.interfaces.MyOnClickListener;
import com.app.twth.ui.finalprocess.FinalProcess;

import java.util.ArrayList;
import java.util.List;


public class FinalProcessTrkAdapter extends RecyclerView.Adapter<FinalProcessTrkAdapter.MyViewHolder> {
    private int type = 0;
    private Context mContext;
    private LayoutInflater mInflater;
    private MyOnClickListener myOnClickListener;
    private List<FinalProcess.ItemInfoDTO> data = new ArrayList<>();

    public FinalProcessTrkAdapter(Context mContext, List<FinalProcess.ItemInfoDTO> data, MyOnClickListener myOnClickListener) {
        this.mContext = mContext;
        this.data = data;
        this.mInflater = LayoutInflater.from(mContext);
        this.myOnClickListener = myOnClickListener;
    }

    public void setData(List<FinalProcess.ItemInfoDTO> data, int type) {
        this.data = data;
        this.type = type;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(ItemFinalprocessLpnListBinding.inflate(mInflater, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ItemFinalprocessLpnListBinding itemBinding;

        public MyViewHolder(ItemFinalprocessLpnListBinding itemBinding) {
            super(itemBinding.getRoot());
            this.itemBinding = itemBinding;
        }

        public void setData(int position) {
            itemView.setTag(position);
            FinalProcess.ItemInfoDTO tallyLPN = data.get(position);
            switch (tallyLPN.getType()){////处理类型 1:指定销毁/2:系统销毁(15天无反馈)/3:上架/4:返还客户/5:重新拍照,可用值:1,2,3,4
                case 1:
                    itemBinding.tvItem.setText(tallyLPN.getTrackingCode() + "(Destroy)");
                    break;
                case 2:
                    itemBinding.tvItem.setText(tallyLPN.getTrackingCode() + "(Destroy)");
                    break;
                case 3:
                    itemBinding.tvItem.setText(tallyLPN.getTrackingCode() + "(Putaway)");
                    break;
                case 4:
                    itemBinding.tvItem.setText(tallyLPN.getTrackingCode() + "(Return)");
                    break;
                case 5:
                    itemBinding.tvItem.setText(tallyLPN.getTrackingCode() + "(Photo)");
                    break;
                default:
                    itemBinding.tvItem.setText(tallyLPN.getTrackingCode() + "(" + tallyLPN.getType() + ")");
                    break;
            }

            itemBinding.tvItem.setOnClickListener(v -> {
                myOnClickListener.OnClick(position);
            });
        }
    }

}
